// const KeyAnimation = require('./module/KeyAnimation');
// const Config = require('./Config');
// const TD = require('./module/TD');

// 引入各页的交互操作
const TabFn = require('./TabFn');
const Main03CardFn = require('./main03');

// 加载页对象
const IndexViewController = function () {
    // 公共变量
    const _that = this;
    const _private = {};
    const _slist = {}; // 用来存储多个swiper对象使用
    _private.mMain = $('.m-main');
    _private.mainWrap = _private.mMain.find('.main-wrap');
    _private.sContainer = _private.mainWrap.find('.swiper-container');
    // 其余屏使用的导航
    _private.sNav = _private.mainWrap.find('.nav02');
    let _text = '首页';
    // 初始化，包括整体页面
    _private.init = function () {
        if (_private.isInit === true) {
            return;
        }
        let _count = true;
        // 主体6屏展示区swiper初始化
        _slist.indexWrap = new Swiper('.swiper-main', {
            // 设置竖屏滚动
            direction: 'vertical',
            // 设置边缘禁止滚动
            resistanceRatio: 0,
            watchSlidesProgress: true,
            onSlideChangeEnd: function (swiper) {
                $('.m-layer').removeClass('show');
                $('.floatMatch').removeClass('show');
                $('.floatMatch').find('.main-page').addClass('show').siblings().removeClass('show');
            },
            onProgress: function (swiper, progress) {
                if (progress < 0.2) {
                    _private.sNav.addClass('index');
                } else {
                    _private.sNav.removeClass('index');
                }
            },
            pagination: '.m-layer .swiper-pagination',
            paginationClickable: true,
            paginationElement: 'div',
            paginationBulletRender: function (swiper, index, className) {
                // let _text = '首页';
                // console.log(_text);
                switch (index) {
                    case 0:
                        _text = '首 页';
                        break;
                    case 1:
                        _text = '关于NI';
                        break;
                    case 2:
                        _text = '赛事品类';
                        break;
                    case 3:
                        _text = '精彩回顾';
                        break;
                    case 4:
                        _text = '大师联盟';
                        break;
                    case 5:
                        _text = '合作伙伴';
                }
                // return '<div class="main-go ' + className + '">' + text + '</div>';
                return `<div class="main-go ${className}"><div class="icon"></div><div class="text">${_text}</div></div>`;
            }
        });

        _private.main03Cards = new Swiper('.swiper-card', {
            initialSlide: 5,
            loop: true,
            effect: 'coverflow',
            slidesPerView: 'auto',
            centeredSlides: true,
            coverflow: {
                rotate: 0,
                stretch: 40,
                depth: 160,
                modifier: 3,
                slideShadows: false
            },
            pagination: '.swiper-card .swiper-pagination',
            paginationClickable: true
        });

        _private.main04Year = new Swiper('.swiper-year', {
            initialSlide: 5,
            // effect : 'fade',
            loop: true,
            pagination: '.swiper-year .swiper-pagination',
            paginationClickable: true
        });

        _private.main05Cont01 = new Swiper('.main05-cont01-swiper', {
            autoHeight: true, // 高度随内容变化
            observer: true,
            observeParents: true,
            pagination: '.main05-cont01-swiper .swiper-pagination',
            paginationClickable: true
        });
        _private.main05Cont02 = new Swiper('.main05-cont02-swiper', {
            autoHeight: true, // 高度随内容变化
            observer: true,
            observeParents: true,
            pagination: '.main05-cont02-swiper .swiper-pagination',
            paginationClickable: true
        });
        _private.main05Cont01 = new Swiper('.hzmt-swiper', {
            autoHeight: true, // 高度随内容变化
            observer: true,
            observeParents: true,
            pagination: '.hzmt-swiper .swiper-pagination',
            paginationClickable: true
        });
        // 菜单绑定事件
        $('.btn-menu').on('click', function () {
            $('.m-layer').addClass('show');
            $('.btn-back').on('click', function () {
                $('.m-layer').removeClass('show');
            });
        });
        // 腾讯视频使用
        let VideoFn = function () {
            let floatVideo = $('.m-float-video');
            let btnClose = floatVideo.find('.btn-close');
            let video = new tvp.VideoInfo();
            let player;
            btnClose.on('click', function () {
                player.pause();
                floatVideo.hide();
                // stage.ableScroll();
            });

            this.show = function (vid) {
                // stage.disableScroll();
                floatVideo.show();
                video.setVid(vid);
                player = new tvp.Player();
                player.create({
                    width: '100%',
                    height: '100%',
                    video: video,
                    modId: 'mod_player',
                    autoplay: true
                    // mod_player是刚刚在页面添加的div容器 autoplay:true
                });
            };
        };
        let videoPlay = new VideoFn();
        // 外部js分离初始化
        TabFn();
        _private.Main03CardFn = new Main03CardFn();
        // 给按钮进行传参vid值
        $('.video-control').on('click', function () {
            if (_count) {
                _count = false;
                console.log($(this));
                let vid = $(this).data('vid');
                console.log($(this).data('vid'));
                videoPlay.show(vid);
                _count = true;
            }
        });
    };

    // 显示
    _that.show = function () {
    };

    // 隐藏
    _that.hide = function () {
        _that.onhide && _that.onhide();
        _private.pageEl.hide();
    };

    _private.init();
};

module.exports = IndexViewController;
